﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Football.ViewModels;
using Football.Models;

namespace Football.Controllers
{
    public class GameController : Controller
    {
        FootballEntities footballDB = new FootballEntities();

        //
        // GET: /Game/

        public ActionResult Index()
        {
            GameIndexViewModel givm = new GameIndexViewModel();

            var gameList = footballDB.Games.OrderBy(game => game.GameStartDate).Take(5);

            givm.Games = gameList;

            return View(givm);
        }

        //
        // GET: /Game/Details/5

        public ActionResult Details(int id)
        {
            var game = footballDB.Games.Find(id);

            GameViewModel gvm = new GameViewModel(game);

            return View(gvm);
        }

        public ActionResult PlayerList( int id )
{
    var game = footballDB.Games.Find(id);

    GameViewModel gvm = new GameViewModel(game);

	return View("Index", game);
}

        //
        // GET: /Game/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Game/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {

                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Game/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Game/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Game/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Game/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
